import platform from '@src/platform';
import { RESOURCE_PREFIX } from '@src/util/linkSwitch'; 
import { t } from '@src/locales';

const pathMap = {
  '/setting/serviceStation/customerPortal': t('common.pageTitle.pageCustomerPortal'),
  '/setting/doMyself/doMyselfSet': t('common.pageTitle.pageCustomerPortal'),
  '/setting/doMyself/wxSet': t('common.pageTitle.pageWxSet'),
  '/setting/doMyself/miniProgramSet': t('common.pageTitle.pageMiniProgramSet'),
  '/setting/doMyself/toastList': t('common.pageTitle.pageToastList'),
  '/foundation/setting/message': t('common.pageTitle.pageSettingMessage'),
  '/setting/message/subManage': t('common.pageTitle.pageSubManage'),
  '/setting/message/smsmessage': t('common.pageTitle.pageSettingSmsmessage'),
  '/foundation/emailMessage': t('common.pageTitle.pageEmailMessage'),
  '/stats/statistics': t('common.pageTitle.pageManagementReport'),
  '/stats/screenData/screenDataView': t('common.pageTitle.pageDataScreen'),
  '/setting/callcenter/stage': t('common.pageTitle.pageCallCenterStage'),
  '/setting/callcenter/workbench': t('common.pageTitle.pageSecurityCallcenterWorkbench'),
  '/im/imConversationList': t('common.pageTitle.pageImConversationList'),
  '/im/conversationLine': t('common.pageTitle.pageConversationLine'),
  '/im/imChat': t('common.pageTitle.pageImImchat'),
  '/payment/paymentBillOnline': t('common.pageTitle.pagePaymentBillOnlineList'),
  '/performance/list': t('common.pageTitle.pagePerformanceList'),
  '/performance/v2/report/desc': t('common.pageTitle.pageReportDesc'),
}

export function setTabTitle() {
  let path = window.location.pathname;
  if(path.indexOf(RESOURCE_PREFIX) > -1) path = path.replace(RESOURCE_PREFIX, '');
  if (window.frameElement) {
    const currentTabId = window.frameElement.dataset.id;
    platform.setTabTitle({
      id: currentTabId,
      title: pathMap[path]
    })
  }
}